{extend name="$base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="WAP_CSS/order_refund.css">
{/block}
{block name="main" }
{php}
	$order_goods_id = request()->get('order_goods_id', 0);
	if(!empty($order_goods_id)){
		$info = api("System.Order.refundDetail",["order_goods_id"=>$order_goods_id]);
		$info = $info['data'];
		if(!empty($info)){
			$detail = $info['refund_detail'];
			$refund_money = $info['total_refund_money'];
			$freight = $info['freight'];
			$shop_info = api("System.Shop.shopOrderReturnSet");
			$shop_info = $shop_info["data"];
		}
	}
{/php}
{notempty name="$info && $detail"}
<form class="main">
	<div class="return-process ns-border-color-gray ns-bg-color-gray-fadeout-60">
		<ul class="clear">
			<li class="step01 ns-text-color-gray">
				<p class="name">{:lang('member_buyers_apply_for_refund')}</p> <span class="ns-bg-color-hover ns-bg-color-gray-shade-20 number">1</span>
				<span class="prcess-line ns-bg-color-hover ns-bg-color-gray-shade-20 prcess-line-r"></span>
			</li>
			<li class="step02 ns-text-color-gray">
				<p class="name">{:lang('member_merchant_processing_refund_request')}</p> <span class="ns-bg-color-hover ns-bg-color-gray-shade-20 prcess-line prcess-line-l"></span>
				<span class="number ns-bg-color-gray-shade-20 ns-bg-color-hover">2</span> <span class="ns-bg-color-hover ns-bg-color-gray-shade-20 prcess-line prcess-line-r"></span>
			</li>
			<li class="step03 ns-text-color-gray">
				<p class="name">{:lang('member_refund_completed')}</p> <span class="ns-bg-color-hover ns-bg-color-gray-shade-20 prcess-line prcess-line-l"></span>
				<span class="number ns-bg-color-gray-shade-20 ns-bg-color-hover">3</span>
			</li>
			<div class="clear"></div>
		</ul>
	</div>
	{if condition="$detail.refund_status eq 0"}
	<div class="form-c" id="form1">
		<div class="row ns-border-color-gray">
			<div class="small-12 columns">
				<label class="ns-text-color-black"><span class="color-red ns-text-color">*</span>{:lang('member_treatment_mode')}：</label>
				<div class="columns-select">
					<select id="refund_require">
						<option value="1" selected="selected">{:lang('member_refund_goods')}</option>
						{if  $detail['shipping_status'] != 0  && $detail['shipping_status'] != 3 && $detail["is_virtual"] == 0}
						<option value="2">{:lang('member_refund_goods_and_money')}</option>
						{/if}
					</select>
				</div>
			</div>
		</div>
		<div class="row ns-border-color-gray">
			<div class="small-12 columns">
				<label class="ns-text-color-black"><span class="color-red ns-text-color">*</span>{:lang('member_refund_reason')}：</label>
				<div class="columns-select">
					<select id="refund_reason">
						<option value="{:lang('member_buyer_and_seller_agrees')}">{:lang('member_buyer_and_seller_agrees')}</option>
						<option value="{:lang('member_wrong_and_no_want')}">{:lang('member_wrong_and_no_want')}</option>
						<option value="{:lang('member_commodity_quality_problems')}">{:lang('member_commodity_quality_problems')}</option>
						<option value="{:lang('member_goods_not_received')}">{:lang('member_goods_not_received')}</option>
						<option value="{:lang('member_other')}">{:lang('member_other')}</option>
					</select>
				</div>
			</div>
		</div>
		{if condition="$refund_money > 0"}
		<div class="row ns-border-color-gray">
			<div class="small-12 columns">
				<label class="ns-text-color-black"><span class="color-red ns-text-color">*</span>{:lang('member_refund_amount')}：</label>
				<div class="columns-input">
					<input id="refund_money" class="maxRefund" type="number" placeholder="{:lang('member_refund_at_most')}{$refund_money}{:lang('element')}" onblur="maxRefund()">
				</div>
			</div>
		</div>
		{/if}
		<input value="{$refund_money}" id="maxRefundMoney" type="hidden" />
		<div class="description-block row ns-border-color-gray">
			<div class="row ns-border-color-gray">
				<div class="small-12 columns">
					<label>{:lang('member_refund_description')}：</label>
				</div>
			</div>
			<textarea rows="5" id="description" placeholder="请输入退款说明"></textarea>
		</div>
		<a class="button primary" href="javascript:void(0)" onclick="btnSave()">{:lang('submit_a_refund_application')}</a>
	</div>
	{elseif condition="$detail.refund_status eq -3" /}
	<div class="form-c" id="form1">
		<div class="row ns-border-color-gray">
			<div class="small-12 columns">
				<label class="ns-text-color-black"><span class="color-red ns-text-color">*</span>{:lang('member_treatment_mode')}：</label> 
				<select id="refund_require">
					<option value="1" selected="selected">{:lang('member_refund_goods')}</option>
					{if  $detail['shipping_status'] != 0  && $detail['shipping_status'] != 3 && $detail["is_virtual"] == 0}
					<option value="2" >{:lang('member_refund_goods_and_money')}</option>
					{/if}
				</select>
			</div>
		</div>
		<div class="row ns-border-color-gray">
			<div class="small-12 columns">
				<label class="ns-text-color-black"><span class="color-red ns-text-color">*</span>{:lang('member_refund_reason')}：</label>
				<select id="refund_reason">
					{if condition="$detail.refund_reason eq lang('member_buyer_and_seller_agrees') "}
						<option value="{:lang('member_buyer_and_seller_agrees')}" selected="selected">{:lang('member_buyer_and_seller_agrees')}</option>
						{else}<option value="{:lang('member_buyer_and_seller_agrees')}">{:lang('member_buyer_and_seller_agrees')}</option>
					{/if}
					{if condition="$detail.refund_reason eq lang('member_wrong_and_no_want')"}
						<option value="{:lang('member_wrong_and_no_want')}" selected="selected">{:lang('member_wrong_and_no_want')}</option>
						{else}<option value="{:lang('member_wrong_and_no_want')}">{:lang('member_wrong_and_no_want')}</option>
					{/if}
					{if condition="$detail.refund_reason eq lang('member_commodity_quality_problems')"}
						<option value="{:lang('member_commodity_quality_problems')}" selected="selected">{:lang('member_commodity_quality_problems')}</option>
						{else}<option value="{:lang('member_commodity_quality_problems')}">{:lang('member_commodity_quality_problems')}</option>
					{/if}
					{if condition="$detail.refund_reason eq lang('member_goods_not_received')"}
						<option value="{:lang('member_goods_not_received')}" selected="selected">{:lang('member_goods_not_received')}</option>
						{else}<option value="{:lang('member_goods_not_received')}">{:lang('member_goods_not_received')}</option>
					{/if}
					{if condition="$detail.refund_reason neq lang('member_buyer_and_seller_agrees') || $detail.refund_reason neq lang('member_wrong_and_no_want') || 
					 $detail.refund_reason neq lang('member_commodity_quality_problems') || $detail.refund_reason neq lang('member_goods_not_received')" ||
					 $detail.refund_reason eq lang('member_other')"
					}
						<option value="{:lang('member_other')}" selected="selected">{:lang('member_other')}</option>
						{else}<option value="{:lang('member_other')}">{:lang('member_other')}</option>
					{/if}
				</select>
			</div>
		</div>
		{if condition="$refund_money > 0"}
		<div class="row ns-border-color-gray">
			<div class="small-12 columns">
				<label class="ns-text-color-black"><span class="color-red ns-text-color">*</span>{:lang('member_refund_amount')}：</label>
				<div style="height:40px;line-height:40px;"> 
					<input value="{$refund_money}" id="refund_money" class="maxRefund" type="number" placeholder="{:lang('member_refund_at_most')}{$refund_money}{:lang('element')}">
				</div>
			</div>
		</div>
		{/if}
		<input value="{$refund_money}" id="maxRefundMoney" type="hidden" />
		{if condition="$detail.refund_reason neq lang('member_buyer_and_seller_agrees') || $detail.refund_reason neq lang('member_wrong_and_no_want') || 
		 $detail.refund_reason neq lang('member_commodity_quality_problems') || $detail.refund_reason neq lang('member_goods_not_received')" ||
		 $detail.refund_reason eq lang('member_other')"
		}
		<div class="description-block row ns-border-color-gray" style="display:block;">
		{else/}
		<div class="description-block row ns-border-color-gray">
		{/if}
			<div class="row ns-border-color-gray">
				<div class="small-12 columns">
					<label>{:lang('member_refund_description')}：</label>
				</div>
			</div>
			<textarea rows="5" id="description" placeholder="请输入退款说明"></textarea>
		</div>
		<a class="button primary" href="javascript:void(0)" onclick="btnSave()">{:lang('submit_a_refund_application')}</a>
	</div>
	{elseif condition="$detail.refund_status eq 1" /}
	<div class="none-goods">
		<div class="text">
			<h4>{:lang('wait_for_the_merchant_to_process_the_refund_request')}</h4>
			<ul class="ns-text-color-gray">
				<li>{:lang('if_the_merchant_agreed_to_refund_will_reach_and_refund_to_your_alipay_account_or_bank_card')}。</li>
			</ul>
		</div>
	</div>
	{elseif condition="$detail.refund_status eq 2" /}
	<!--已收到货 begin-->
	<div class="seller-agree" id="form2">
		<h4 class="ns-text-color-black">{:lang('member_return_and_fill')}</h4>
		<h5 class="ns-text-color-black">1、{:lang('please_return_the_goods')}</h5>
		<p class="explanation ns-text-color-black">
			{:lang('member_use_or_surface')}。<br />
			{:lang('member_return_address')}： 
			<span class="address ns-text-color-black">
			{if condition="$shop_info.shop_address neq ''"}
				{$shop_info.shop_address}&nbsp;&nbsp;{$shop_info.seller_name}&nbsp;&nbsp;{$shop_info.seller_mobile}&nbsp;&nbsp;{$shop_info.seller_zipcode}
			{else /}
				{:lang('member_no_delivery_address_yet')}
			{/if}
			</span>
		</p>
		<h5 class="ns-text-color-black">
			2、{:lang('member_logistics_information')} <small class="ns-text-color-gray">（{:lang('member_application_closed')}）</small>
		</h5>
		<div class="express-form">
			<div class="row ns-border-color-gray">
				<label class="ns-text-color-black"><span class="color-red ns-text-color">*</span>{:lang('member_logistics_company')}：</label>
				<input type="text" id="LogisticsCompany" class="ns-border-color-gray" />
			</div>
			<div class="row ns-border-color-gray">
				<label class="ns-text-color-black"><span class="color-red ns-text-color">*</span>{:lang('member_waybill_number')}：</label>
				<input type="text" id="ExpressNo" class="ns-border-color-gray" />
			</div>
			<div class="row ns-border-color-gray">
				<a class="button primary" href="javascript:void(0)" onclick="ExpressSave()">{:lang('member_submit')}</a>
			</div>
		</div>
	</div>
	{elseif condition="$detail.refund_status eq 3" /}
	<div class="none-goods">
		<div class="text">
			<h4 class="ns-text-color-black">{:lang('member_waiting_for_merchant')}</h4>
			<ul class="ns-text-color-gray">
				<li>{:lang('if_the_merchant_agreed_to_refund_will_reach_and_refund_to_your_alipay_account_or_bank_card')}</li>
			</ul>
		</div>
	</div>
	{elseif condition="$detail.refund_status eq 4" /}
	<!--等待卖家同意退款 begin-->
	<div class="wait-seller-agree">
		<div class="text">
			<h4 class="ns-text-color-black">{:lang('member_successfully_applied_for_refund')}</h4>
		</div>
	</div>
	<!--等待卖家同意退款 begin-->
	{elseif condition="$detail.refund_status eq 5" /}
	<!--step03 begin-->
	<div class="return-success">
		<div class="text">
			<h4 class="ns-text-color-black">{:lang('member_refund_successful')}</h4>
			<p class="time ns-text-color-gray">{:lang('refund_success_time')}:{$detail.refund_time | getTimeStampTurnTime}</p>
			{if $detail.refund_real_money > 0}
				<p class="money ns-text-color-black"><strong class="ns-text-color">{$detail.refund_real_money}</strong>{:lang('element')}通过{$detail.refund_type_name}已退还</p>
			{/if}
			{if $detail.refund_balance_money > 0}
				<p class="money ns-text-color-black"><strong class="ns-text-color">{$detail.refund_balance_money}</strong>{:lang('element')}已退还到余额</p>
			{/if}
		</div>
	</div>
	{elseif condition="$detail.refund_status eq -1" /}
	<!--卖家拒绝 begin-->
	<div class="disagree-return">
		<div class="text">
			<h4 class="ns-text-color-black">{:lang('member_seller_rejects')}</h4>
			<div class="operate"></div>
		</div>
	</div>
	{elseif condition="$detail.refund_status eq -2" /}
	<div class="return-success">
		<div class="text">
			<h4 class="ns-text-color-black">{:lang('member_refund_closed')}</h4>
		</div>
	</div>
	{/if}
</form>
{else/}
<script>history.back();</script>
{/notempty}
{/block}
{block name="script"}
{notempty name="$info"}
<script>
var order_id = {$detail.order_id};
var itemId ={$detail.order_goods_id};
$(function() {
	var refund_status = {$detail.refund_status};
	if(refund_status == ""){
		$(".step01").addClass("selected ns-text-color-hover");
		$(".step01").find('*').addClass("selected");
	}else if(refund_status == 0){
		$(".step01").addClass("selected ns-text-color-hover");
		$(".step01").find('*').addClass("selected");
	}else if(refund_status == 5){
		$(".step01").addClass("selected ns-text-color-hover");
		$(".step01").find('*').addClass("selected");
		$(".step02").addClass("selected ns-text-color-hover");
		$(".step02").find('*').addClass("selected");
		$(".step03").addClass("selected ns-text-color-hover");
		$(".step03").find('*').addClass("selected");
	}else if(refund_status < 0){
		$(".step01").addClass("selected ns-text-color-hover");
		$(".step01").find('*').addClass("selected");
		$(".step02").addClass("selected ns-text-color-hover");
		$(".step02").find('*').addClass("selected");
	}else{
		$(".step01").addClass("selected ns-text-color-hover");
		$(".step01").find('*').addClass("selected");
		$(".step02").addClass("selected ns-text-color-hover");
		$(".step02").find('*').addClass("selected");
	}
	$("#refund_reason").change(function(){
		if($(this).val()=="{:lang('member_other')}"){
			$(".description-block").show();
		}else{
			$(".description-block").hide();
		}
	})
});

function ExpressSave(){
	var LogisticsCompany=$("#LogisticsCompany").val();
	var ExpressNo=$("#ExpressNo").val();
	if(LogisticsCompany==""){
		$("#LogisticsCompany").focus();
	}else if(ExpressNo==""){
		$("#ExpressNo").focus();
	}else{
		api("System.Order.orderRefund",{ "order_id": order_id, "order_goods_id": itemId, "refund_express_company": LogisticsCompany, "refund_shipping_no": ExpressNo },function (res) {
			if(res.data>0){
				toast("{:lang('successful_application_for_refund')}",__URL("APP_MAIN/Member/index"));
			}else{
				toast("{:lang('failed_to_apply_for_refund')}");
			}
		});
	}
}

function btnSave() {
	var refund_require = $("#refund_require").val();
	var refund_reason = $("#refund_reason").val();
	var refund_money = $("#refund_money").val();//退款金额
	if(refund_money == undefined){
		refund_money = 0;
	}
	var description = $("#description").val();//退款说明
	var num2 = parseFloat($("#maxRefundMoney").val());
	if(refund_money == "" && refund_money !== 0){
		$("#refund_money").focus();
		toast("{:lang('please_enter_the_refund_amount')}");
		return;
	}
	if(refund_money >= 0){
		if (refund_money <0 || refund_money >num2 ) {
			$("#refund_money").focus();
			toast("{:lang('member_beyond_refund_amount')}");
			return;
		}
	}
	if(refund_reason == '{:lang('member_other')}'){
		refund_reason = description;
		if(refund_reason == ""){
			toast("{:lang('member_please_enter_refund_statement')}");
			return false;
		}
	}
	
	api("System.Order.applyOrderRefund", {
		"order_id": order_id,
		"order_goods_id": itemId,
		"refund_type": refund_require,
		"refund_require_money": refund_money,
		"refund_reason": refund_reason
	},function (res) {
		if(res.data>0){
			toast("操作成功",window.location.reload());
		}else{
			toast(res.message);
		}
	});
}

//最多退款金额
function maxRefund() {
	var num = parseFloat($("#refund_money").val());
	var num2 = parseFloat($("#maxRefundMoney").val());
	if (num < 0 || num >num2) {
		$("#refund_money").focus();
		toast("{:lang('member_beyond_refund_amount')}");
	}
}
</script>
{/notempty}
{/block}